# 导入内置模块
from flask import session,render_template,current_app
# 导入蓝图
from . import news_blue
from info.models import User


@news_blue.route('/')
def index():
    # 使用上下文对象获取userid_id
    user_id = session.get('user_id')
    user = None
    # 查询mysql
    try:
        user = User.query.get(user_id)
    except Exception as e:
        current_app.logger.error(e)

    # 定义字典储存数据
    dict = {'user_info':user.to_dict() if user else None}

    return render_template('/news/index.html',dict=dict)


@news_blue.route('/favicon.ico')
def favicon():
    # 用flask自带的函数发送静态文件
    return current_app.send_static_file('/news/favicon.ico')